package 代码记录.校招笔试真题.笔试真题_2023.博乐科技;

/**
 * @author zx
 * @create 2023-02-19 20:47
 */
public class Test3 {
    /**
     * @return 66.7%
     * 给定一个正数n,求在[1, n]范围内，每个字符(0-9)出现了多少次
     * 时间复杂度太大
     */
    public String CountNumber (int n) {
        String res = "";
        int[] arr = new int[10];
        for(int i = 1;i <= n;i++){
            int temp = i;
            while(temp != 0){
                int k = temp % 10;
                temp = temp / 10;
                arr[k]++;
            }
        }
        for(int i = 0;i < arr.length - 1;i++){
            res = res + arr[i] + " ";
        }
        res += arr[arr.length - 1];
        return res;
    }

}
